﻿using System;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Media;

namespace AccessControl.Wpf.Converters
{
	class ImageByteToImageSourceConverter : IValueConverter
	{

		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			byte[] aBytes = (byte[])value;

			if (aBytes == null || aBytes.Length == 0)
				return null;

			MemoryStream ms = new MemoryStream(aBytes);
			BitmapImage image = new BitmapImage();
			image.BeginInit();
			image.StreamSource = ms;
			image.EndInit();
			return image;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
